from pylab import *
from numpy import *



def Graytodec(g):

#g=[1,0,1,1,0,0,0,1]

    b=[g[0]]

    for i in range(1,8):
    
        if g[i]==0:
            b.append(b[i-1])
        if g[i]==1:
            if b[i-1]==0:
                b.append(1)
            if b[i-1]==1:
                b.append(0)


    n8=b[0]*(2**7)
    n7=b[1]*(2**6)
    n6=b[2]*(2**5)
    n5=b[3]*(2**4)
    n4=b[4]*(2**3)
    n3=b[5]*(2**2)
    n2=b[6]*(2**1)
    n1=b[7]*(2**0)

    num=n1+n2+n3+n4+n5+n6+n7+n8
    
    
    return num


v=[[1,0,0,1,1,1,0,0],[1,1,0,1,0,0,0,0],[0,0,0,1,1,1,1,1]]

p=[]


for f in v:
    p.append(Graytodec(f))

print p

#http://www.unicrom.com/dig_conversion_binario-GRAY_GRAY_Binario.asp
